﻿using System;

namespace StudentManagementSystem
{
    class Program
    {
        static void Main(string[] args)
        {
            // 打开数据库连接
            DBHelper.OpenConnection();

            // 创建一些学校对象
            School s1 = new School(1, "清华大学");
            School s2 = new School(2, "北京大学");
            School s3 = new School(3, "武汉大学");

            // 添加学校到数据库
            DBHelper.AddSchool(s1);
            DBHelper.AddSchool(s2);
            DBHelper.AddSchool(s3);

            // 创建一些班级对象，并指定所属的学校
            Class c1 = new Class(1, "计算机科学与技术1班", s1);
            Class c2 = new Class(2, "计算机科学与技术2班", s1);
            Class c3 = new Class(3, "软件工程1班", s1);
            Class c4 = new Class(4, "软件工程2班", s1);
            Class c5 = new Class(5, "数学与应用数学1班", s2);
            Class c6 = new Class(6, "数学与应用数学2班", s2);
            Class c7 = new Class(7, "物理学1班", s2);
            Class c8 = new Class(8, "物理学2班", s2);
            Class c9 = new Class(9, "经济学1班", s3);
            Class c10 = new Class(10, "经济学2班", s3);
            Class c11 = new Class(11, "金融学1班", s3);
            Class c12 = new Class(12, "金融学2班", s3);

            // 添加班级到数据库
            DBHelper.AddClass(c1);
            DBHelper.AddClass(c2);
            DBHelper.AddClass(c3);
            DBHelper.AddClass(c4);
            DBHelper.AddClass(c5);
            DBHelper.AddClass(c6);
            DBHelper.AddClass(c7);
            DBHelper.AddClass(c8);
            DBHelper.AddClass(c9);
            DBHelper.AddClass(c10);
            DBHelper.AddClass(c11);
            DBHelper.AddClass(c12);

            // 创建一些学生对象，并指定所属的班级
            Student stu1 = new Student(1, "张三", 20, "男");
            Student stu2 = new Student(2, "李四", 21, "男");
            Student stu3 = new Student(3, "王五", 19, "男");
            Student stu4 = new Student(4, "赵六", 22, "男");
            Student stu5 = new Student(5, "小红", 20, "女");
            Student stu6 = new Student(6, "小明", 21, "男");
            Student stu7 = new Student(7, "小花", 19, "女");
            Student stu8 = new Student(8, "小刚", 22, "男");
            c1.AddStudent(stu1);
            c2.AddStudent(stu2);
            c3.AddStudent(stu3);
            c4.AddStudent(stu4);
            c5.AddStudent(stu5);
            c6.AddStudent(stu6);
            c7.AddStudent(stu7);
            c8.AddStudent(stu8);

            // 添加学生到数据库
            DBHelper.AddStudent(stu1);
            DBHelper.AddStudent(stu2);
            DBHelper.AddStudent(stu3);
            DBHelper.AddStudent(stu4);
            DBHelper.AddStudent(stu5);
            DBHelper.AddStudent(stu6);
            DBHelper.AddStudent(stu7);
            DBHelper.AddStudent(stu8);

            // 查询并显示所有学校信息
            var schools = DBHelper.GetAllSchools();
            foreach (var school in schools)
            {
                school.ShowInfo();
            }

            // 查询并显示所有班级信息
            var classes = DBHelper.GetAllClasses();
            foreach (var c in classes)
            {
                c.ShowInfo();
            }

            // 查询并显示所有学生信息
            var students = DBHelper.GetAllStudents();
            foreach (var s in students)
            {
                s.ShowInfo();
            }

            // 修改一个学校的名称，并显示修改后的信息
            s1.Name = "清华大学（新）";
            DBHelper.UpdateSchool(s1);
            s1.ShowInfo();

            // 删除一个班级，并显示删除后的信息
            DBHelper.DeleteClass(c12);
            c12.ShowInfo();

            // 添加一个学生，并显示添加后的信息
            Student stu9 = new Student(9, "小李", 20, "男");
            c9.AddStudent(stu9);
            DBHelper.AddStudent(stu9);
            stu9.ShowInfo();

            // 显示所有日志信息
            LogHelper.ShowAllLogs();

            // 关闭数据库连接
            DBHelper.CloseConnection();
        }
    }
}


